//
//  KeyBoardManager.m
//  VMall
//
//  Created by dev on 2017/5/5.
//  Copyright © 2017年 mohao. All rights reserved.
//

#import "KeyBoardManager.h"

@implementation KeyBoardManager

@synthesize animationDuration,keyHeight,keyBoardShow;

+(instancetype)sharedManager
{
    static dispatch_once_t queue;
    static KeyBoardManager * manager = nil;
    
    dispatch_once(&queue, ^{
        manager = [[KeyBoardManager alloc]init];
    });
    
    return manager;
}

-(instancetype)init
{
    self = [super init];
    
    if (self) {
        // 添加观察
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
        
    }
    
    return self;
}

- (void)keyboardWillShow:(NSNotification *)notification {
    
    keyBoardShow = YES;
    
    //获取键盘高度
    NSDictionary *info = [notification userInfo];
    animationDuration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
    NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGSize keyboardSize = [value CGRectValue].size;
    keyHeight = keyboardSize.height;
    
}


- (void)keyboardWillHide:(NSNotification *)notification {
    
    //获取键盘高度
    NSDictionary *info = [notification userInfo];
    animationDuration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
    NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGSize keyboardSize = [value CGRectValue].size;
    keyHeight = keyboardSize.height;

}

- (void)keyboardDidHide:(NSNotification *)notification {

    keyBoardShow = NO;
}


@end
